package com.martin.lib_base.model

import androidx.lifecycle.MutableLiveData

/**
 * @desc：验证码发送逻辑类
 */
class CodeModel(private val text: String = "获取验证码") {

    // 验证码
    val code = MutableLiveData("")

    // 倒计时文案
    val sendText = MutableLiveData(text)

    // 是否可以点击
    val sendEnabled = MutableLiveData(true)

    // 倒计时
    private val countDownModel = CountDownModel(60, 1, {
        sendText.value = "${it}秒后重发"
        sendEnabled.value = false
    }) {
        sendText.value = text
        sendEnabled.value = true
    }

    fun startCountDown() {
        countDownModel.start()
        sendEnabled.value = false
    }

    fun cancelCountDown() {
        sendText.value = text
        countDownModel.cancel()
        sendEnabled.value = true
    }

}